package yangsw87.utils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class OracleJDBC {
	private static final String DRV = "oracle.jdbc.OracleDriver";
	private static final String URL = "jdbc:oracle:thin:@//112.216.253.122:1521/xe";
	private static final String USR = "yangsw87";
	private static final String PWD = "yangsw87";
	
	private static final String ZIPCODE = "zipcode"; // 우편번호검색계정

	// oracle JDBC 객체 생성
	public static Connection openConn() {
		Connection conn = null;
		try {
			Class.forName(DRV);
			conn = DriverManager.getConnection(URL, USR, PWD);
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		return conn;
	}
	
	// oracle JDBC 객체 종료 및 해제
	public static void closeConn(Connection c, PreparedStatement p, ResultSet r) {
		if(r != null)
			try {
				r.close();
			} catch (Exception ex) {
			}
		if(p != null)
			try {
				p.close();
			} catch (Exception ex) {
			}
		if(c != null)
			try {
				c.close();
			} catch (Exception ex) {
			}
	}
	
	// 우편번호 검색시 사용할 접속정보
	public static Connection openZipcode() {
		Connection conn = null;
		try {
			Class.forName(DRV);
			conn = DriverManager.getConnection(URL, ZIPCODE, ZIPCODE);
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		return conn;
	}
	
	public static void closeZipcode(Connection c, PreparedStatement p, ResultSet r) {
		if(r != null)
			try {
				r.close();
			} catch (Exception ex) {
			}
		if(p != null)
			try {
				p.close();
			} catch (Exception ex) {
			}
		if(c != null)
			try {
				c.close();
			} catch (Exception ex) {
			}
	}
}
